package 牛客;

public class p72二叉树的镜像 {

    public class TreeNode {
     int val = 0;
     TreeNode left = null;
     TreeNode right = null;
     public TreeNode(int val) {
     this.val = val;
   }
    }

    public TreeNode Mirror (TreeNode pRoot) {
        // write code here
        if (pRoot==null) {
            return pRoot;
        }

        if (pRoot.left==null && pRoot.right==null) {
            return pRoot;
        }

        TreeNode tmp;
        tmp=pRoot.left;
        pRoot.left=pRoot.right;
        pRoot.right=tmp;

        if (pRoot.left!=null) {
            Mirror(pRoot.left);
        }
        if (pRoot.right!=null) {
            Mirror(pRoot.right);
        }
        return pRoot;
    }
}
